/*
 * Copyright (c) 2017 22420103@QQ.COM 版权所有
 */
package com.lehe.config;

import com.lehe.interceptors.AdminAuthenticationInterceptor;
import com.lehe.interceptors.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


/**
 * 拦截器配置<br>
 *
 * @author 王丹
 * @date 2017-02-26<br>
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter{

	@Autowired
	@Qualifier("authenticationInterceptor")
	private AuthenticationInterceptor authenticationInterceptor;

	@Autowired
	@Qualifier("adminAuthenticationInterceptor")
	private AdminAuthenticationInterceptor adminAuthenticationInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    	//访问拦截
        registry.addInterceptor(authenticationInterceptor)
        .excludePathPatterns(
        		"/index/**",
        		"/error",
        		"/login",
        		"/admin",
        		"/admin/**",
        		"/login/**",
                "/exception/**"
        		).addPathPatterns("/**");
        
        //admin访问拦截
       
        registry.addInterceptor(adminAuthenticationInterceptor)
        .excludePathPatterns(
        		"/index/**",
        		"/error",
        		"/login",
        		"/login/**",
                "/exception/**"
        		).addPathPatterns("/admin","/admin/**");
    }

}
